------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\Users\sgolder\Dropbox\Portfolio Allocation\replication\figure5.log
  log type:  text
 opened on:  30 Mar 2017, 13:56:18

. set more off

. #delimit ;
delimiter now ;
. *     ***************************************************************** *;
. *     ***************************************************************** *;
. *       File-Name:      africancabinets_figure5.do                      *;
. *       Date:           September 19, 2016                              *;
. *       Author:         Molly Ariotti and Sona Golder                   *;
. *       Purpose:        Produce Figure 5 in appendix for CPS African    *;
. *                       portfolio allocation paper.                     *;
. *           Input File:     africa.dta, europe.dta                          *;
. *       Output File:    figure5.log, nonformateur.eps                   *;
. *                       formateur.eps                                   *;
. *       Data Output:    none                                            *;
.              *       Previous file:  none                                            *;
. *       Machine:        laptop                                                          *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. use "\Users\sgolder\Dropbox\Portfolio Allocation\replication\Africa.dta";

.  sum;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
 countryname |          0
 countrycode |         84    5.559524    2.552349          1          9
 cabinetcode |         84    13.89286    8.034591          1         28
     cowcode |         84    517.8452    69.14373        403        590
        year |         84    2002.357    6.825965       1990       2014
-------------+---------------------------------------------------------
presidential |         84    .3690476    .4854451          0          1
   formateur |         84    .3095238    .4650739          0          1
  portfolios |         84     7.02381    6.860005          1         26
governmen~os |         84    21.08333    6.637259          9         35
 party_seats |         84    39.91667    56.69368          1        279
-------------+---------------------------------------------------------
governmen~ts |         84    115.0952    86.61028         39        377
      region |         84           1           0          1          1
portfolios~e |         84    .3333333     .282168   .0344828   .9545454
   seatshare |         84    .3333333    .2628826   .0034843    .990099
       party |         84    25.91667    13.80083          1         48
-------------+---------------------------------------------------------
        code |         84    105573.4    2560.162     101001     109028

. desc;

Contains data from \Users\sgolder\Dropbox\Portfolio Allocation\replication\Africa.dta
  obs:            84                          
 vars:            16                          30 Mar 2017 12:13
 size:         4,368                          
------------------------------------------------------------------------------------------------------------------
              storage   display    value
variable name   type    format     label      variable label
------------------------------------------------------------------------------------------------------------------
countryname     str21   %21s                  country name
countrycode     byte    %8.0g                 country code
cabinetcode     byte    %8.0g                 cabinet code
cowcode         int     %8.0g                 cow code
year            int     %8.0g                 year in which government begins
presidential    byte    %8.0g                 1 = presidential, 0 = parliamentary
formateur       byte    %8.0g                 1 = formateur, 0 = otherwise
portfolios      byte    %8.0g                 number of portfolios per party
government_po~s byte    %8.0g                 number of portfolios in the government
party_seats     int     %8.0g                 number of legislative seats per party
government_se~s int     %8.0g                 number of seats controlled by government
region          byte    %8.0g                 1=Africa, 2=Western Europe, 3=Latin America
portfolioshare  float   %9.0g                 party share of govt portfolios
seatshare       float   %9.0g                 party share of leg seats controlled by govt
party           long    %9.0g      party      party number or acronym
code            float   %9.0g                 region, country code, cabinet code
------------------------------------------------------------------------------------------------------------------
Sorted by: 

. *     ****************************************************************  *;
. *       Drop African cabinets where there is no formateur coded.        *;
. *       (One in Guinea-Bissau, one in Sao Tome & Principe               *;
. *     ****************************************************************  *;
. drop if cabinetcode == 5;
(5 observations deleted)

. drop if cabinetcode == 23;
(3 observations deleted)

. *     ****************************************************************  *;
. *       Add Europe data from Warwick and Druckman (2006)                *;
. *     ****************************************************************  *;
. append using "\Users\sgolder\Dropbox\Portfolio Allocation\replication\Europe.dta";
(note: variable year was int, now float to accommodate using data's values)
(note: variable party was long, now double to accommodate using data's values)
(note: variable party_seats was int, now float to accommodate using data's values)
(note: variable formateur was byte, now float to accommodate using data's values)
(note: variable government_portfolios was byte, now float to accommodate using data's values)
(note: variable countrycode was byte, now float to accommodate using data's values)
(note: variable portfolios was byte, now float to accommodate using data's values)
(note: variable cabinetcode was byte, now float to accommodate using data's values)
(note: variable region was byte, now float to accommodate using data's values)
(note: variable cowcode was int, now float to accommodate using data's values)
(note: variable government_seats was int, now float to accommodate using data's values)
(note: variable presidential was byte, now float to accommodate using data's values)

.  *     ****************************************************************  *;
. *       Drop European cabinets where there is no formateur coded.       *;
. *      (These are caseno 531, 532, 533, 534, 542,543, 617, 858, 859)    *;
. *     ****************************************************************  *;
. drop if code == 205097;
(3 observations deleted)

. drop if code == 205098;
(2 observations deleted)

. drop if code == 205099;
(2 observations deleted)

. drop if code == 205100;
(2 observations deleted)

. drop if code == 205108;
(4 observations deleted)

. drop if code == 205109;
(4 observations deleted)

. drop if code == 207130;
(3 observations deleted)

. drop if code == 209184;
(6 observations deleted)

. drop if code == 209185;
(4 observations deleted)

. *     ****************************************************************  *;
. *       Create regional dummy variables                                 *;
. *     ****************************************************************  *;
. gen africa = . ;
(853 missing values generated)

. replace africa = 1 if region==1;
(76 real changes made)

. replace africa = 0 if region==2;
(777 real changes made)

. replace africa = 0 if region==3;
(0 real changes made)

. gen europe = . ;
(853 missing values generated)

. replace europe = 0 if region==1;
(76 real changes made)

. replace europe = 1 if region==2;
(777 real changes made)

. replace europe = 0 if region==3;
(0 real changes made)

. gen america = . ;
(853 missing values generated)

. replace america = 0 if region==1;
(76 real changes made)

. replace america = 0 if region==2;
(777 real changes made)

. replace america = 1 if region==3;
(0 real changes made)

. *     ****************************************************************  *;
. *       Create interaction terms for analysis in Table 1                *;
. *     ****************************************************************  *;
. gen seatshare_africa=africa*seatshare;

. gen formateur_africa=africa*formateur;

. *     ****************************************************************  *;
. *       Observed range of Seatshare for non-formateur parties.          *;
. *     ****************************************************************  *;
. sum seatshare if formateur==0;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
   seatshare |        568    .2053153    .1472838   .0034843   .7277778

. *     ****************************************************************  *;
. *       Observed range of Seatshare for formateur parties.              *;
. *     ****************************************************************  *;
. sum seatshare if formateur==1;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
   seatshare |        285    .5908101    .2020164   .0433604    .990099

. *     ****************************************************************  *;
. *       Table 1, Model 4 combined                                       *;
. *     ****************************************************************  *;
. regress portfolioshare seatshare formateur africa seatshare_africa formateur_africa, robust;

Linear regression                               Number of obs     =        853
                                                F(5, 847)         =    1713.93
                                                Prob > F          =     0.0000
                                                R-squared         =     0.9069
                                                Root MSE          =     .06546

----------------------------------------------------------------------------------
                 |               Robust
  portfolioshare |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-----------------+----------------------------------------------------------------
       seatshare |   .8346488   .0137715    60.61   0.000     .8076186    .8616789
       formateur |  -.0310149   .0073525    -4.22   0.000    -.0454462   -.0165837
          africa |  -.0614534   .0086882    -7.07   0.000    -.0785063   -.0444005
seatshare_africa |   .0230141   .0403582     0.57   0.569    -.0561997    .1022279
formateur_africa |    .161654   .0268466     6.02   0.000     .1089602    .2143477
           _cons |   .0654554   .0035636    18.37   0.000     .0584608      .07245
----------------------------------------------------------------------------------

. *     ****************************************************************  *;
. *       Collect the pieces necessary for Figure 4 (in the appendix)     *;
. *     ****************************************************************  *;
. matrix b=e(b);

. matrix V=e(V);

. scalar b3=b[1,3];

. scalar b4=b[1,4];

. scalar b5=b[1,5];

. scalar varb3=V[3,3];

. scalar varb4=V[4,4];

. scalar varb5=V[5,5];

. scalar covb3b4=V[3,4];

. scalar covb3b5=V[3,5];

. scalar list b3 b4 b5 varb3 varb4 varb5 covb3b4 covb3b5;
        b3 = -.06145341
        b4 =  .02301411
        b5 =  .16165395
     varb3 =  .00007548
     varb4 =  .00162878
     varb5 =  .00072074
   covb3b4 = -.00019029
   covb3b5 =  .00004513

. *     ****************************************************************  *;
. *       Create values for horizontal axis                               *;
. *     ****************************************************************  *;
. set obs 1000;
number of observations (_N) was 853, now 1,000

. gen MVZ = (_n-1)/1000;

. *     ****************************************************************  *;
. *       Create information for non-formateur parties                    *;
. *     ****************************************************************  *;
. gen marginal_nonformateur = b3+b4*MVZ;

. gen se_nonformateur = sqrt(varb3+varb4*(MVZ^2)+2*MVZ*covb3b4);

. gen bound = 1.96*se_nonformateur;

. gen upper = marginal_nonformateur+bound;

. gen lower = marginal_nonformateur-bound;

. gen yline=0;

. *     ****************************************************************  *;
. *       Produce Figure 5 (appendix), Panel a: Non-formateur parties     *;
. *     ****************************************************************  *;
. graph twoway hist seatshare if formateur==0 & seatshare<0.74, width(0.04) percent color(gs15) yaxis(2)
>     || line marginal_nonformateur MVZ if MVZ<0.74 & MVZ>0.002, clpattern(solid) clwidth(medthick) clcolor(black)
>  yaxis(1)
>     || line lower MVZ if MVZ<0.74 & MVZ>0.002, clpattern(dash) clwidth(thin) clcolor(red)
>     || line upper MVZ if MVZ<0.74 & MVZ>0.002, clpattern(dash) clwidth(thin) clcolor(red)
>     || line yline MVZ, clpattern(solid) clwidth(thin) clcolor(black)
>     ||,
>     xlabel(0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0, nogrid labsize(2.5))
>     ylabel(-0.15 -0.12 -0.09 -0.06 -0.03 0 0.03, axis(1) nogrid labsize(2.5))
>     ylabel(0 3 6 9 12 15 18, axis(2) nogrid labsize(2.5) labcolor(gs12) tlcolor(gs12))
>         yscale(noline alt)
>         yscale(noline alt axis(2))
>         xscale(noline)
>         legend(off)
>         title("{stSerif:(a) Non-Formateur Parties}",  size(3.5))
>         xtitle("{stSerif:Share of Government's Legislative Seats}",  size(3) height(7) )
>         ytitle("{stSerif:Percentage of Observations}", color(gs12) axis(2) size(3) margin(5 0 0 0))
>         ytitle("{stSerif:Marginal Effect of Africa}", size(3) height(7)) 
>         scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white));

.        graph export "C:\Users\sgolder\Dropbox\Portfolio Allocation\replication\nonformateur.eps", replace;
(file C:\Users\sgolder\Dropbox\Portfolio Allocation\replication\nonformateur.eps written in EPS format)

. *     ****************************************************************  *;
. *       Calculating percentage of observations that fall in region of   *;
. *       significance 565/568 = 99%                                      *;
. *     ****************************************************************  *;
. list countryname cabinetcode year seatshare if seatshare>0.667 & formateur==0;

      +---------------------------------------+
      | count~me   cabine~e   year   seatsh~e |
      |---------------------------------------|
 623. |    Italy        171   1980   .7277778 |
 628. |    Italy        172   1981   .7100271 |
 634. |    Italy        173   1982   .7100271 |
      +---------------------------------------+

. sum cabinetcode if formateur==0;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
 cabinetcode |        568    120.3944    78.06039          1        268

. *     ****************************************************************  *;
. *       Create information for formateur parties                        *;
. *     ****************************************************************  *;
.               gen marginal_formateur = b3+b4*MVZ + b5;

. gen se_formateur = sqrt(varb3+varb4*(MVZ^2)+2*MVZ*covb3b4 + varb5+2*covb3b5);

. gen bound2 = 1.96*se_formateur;

. gen upper2 = marginal_formateur+bound2;

. gen lower2 = marginal_formateur-bound2;

. *     ****************************************************************  *;
. *       Produce Figure 5 (appendix), Panel b: Formateur parties         *;
. *     ****************************************************************  *;
. graph twoway hist seatshare if formateur==1 & seatshare<0.99 & seatshare>0.04, width(0.04) percent color(gs15) y
> axis(2)
>     || line marginal_formateur MVZ if MVZ<0.99 & MVZ>0.042, clpattern(solid) clwidth(medthick) clcolor(black) ya
> xis(1)
>     || line lower2 MVZ if MVZ<0.99 & MVZ>0.042, clpattern(dash) clwidth(thin) clcolor(red)
>     || line upper2 MVZ if MVZ<0.99 & MVZ>0.042, clpattern(dash) clwidth(thin) clcolor(red)
>     || line yline MVZ, clpattern(solid) clwidth(thin) clcolor(black)
>     ||,
>     xlabel(0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0, nogrid labsize(2.5))
>     ylabel(0 0.05 0.10 0.15 0.20 0.25, axis(1) nogrid labsize(2.5))
>     ylabel(0 3 6 9 12, axis(2) nogrid labsize(2) labcolor(gs12) tlcolor(gs12))
>         yscale(noline alt)
>         yscale(noline alt axis(2))
>         xscale(noline)
>         legend(off)
>         title("{stSerif:(b) Formateur Parties}",  size(3.5))
>         xtitle("{stSerif:Share of Government's Legislative Seats}",  size(3) height(7) )
>         ytitle("{stSerif:Percentage of Observations}", color(gs12) axis(2) size(3) margin(5 0 0 0))
>         ytitle("{stSerif:Marginal Effect of Africa}", size(3) height(7)) 
>         scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white));

.             graph export "C:\Users\sgolder\Dropbox\Portfolio Allocation\replication\formateur.eps", replace;
(file C:\Users\sgolder\Dropbox\Portfolio Allocation\replication\formateur.eps written in EPS format)

. log close;
      name:  <unnamed>
       log:  C:\Users\sgolder\Dropbox\Portfolio Allocation\replication\figure5.log
  log type:  text
 closed on:  30 Mar 2017, 13:56:20
------------------------------------------------------------------------------------------------------------------
